package main

import "fmt"

func main() {
	//map声明
	var map1 map[string]string
	//在使用map的时候需要先分配空间
	map1 = make(map[string]string, 3)
	map1["nanfeng"] = "doumingquan"
	map1["lanting"] = "doumingquan"
	fmt.Println(map1)

	//第二种方式
	map2 := make(map[string]string, 2)
	map2["zhangsan"] = "lanbo"
	map2["lisi"] = "zhangsan"
	fmt.Println(map2)

	//第三种方式 声明并赋值
	map3 := map[string]string{
		"nanfeng": "mingquan",
		"lanting": "mingquan",
	}
	fmt.Println(map3)

	//使用
	city := make(map[string]string, 3)
	city1 := map[string]string{
		"china":   "beijing",
		"america": "washton",
		"japan":   "tokyo",
	}
	fmt.Println(city, city1)

	//修改map
	city1["china"] = "shanghai"
	fmt.Println(city1)

	//删除map元素
	delete(city1, "china")
	fmt.Println(city1)
	updateMap(city1)
	fmt.Println(city1)

	for key, val := range city1 {
		fmt.Println(key, val)
	}
}

//引用传递给map添加一个值
func updateMap(params map[string]string) {
	params["england"] = "london"
}
